package com.baselibrary.test.MVP.Main9Activity.model;

import com.baselibrary.libs.Utils.Toast.UtilsToast;
import com.baselibrary.libs.Utils.log.LogUtils;
import com.baselibrary.libs.Utils.netUtils.NoHttp.queue.Request_netWork;
import com.baselibrary.libs.Utils.netUtils.NoHttp.queue.Request_netWork_error;
import com.baselibrary.libs.design_mode.Observable_demo.Observer.BaseObserver;
import com.baselibrary.libs.design_mode.Observable_demo.Observer.NetTool;
import com.baselibrary.test.MVP.Main9Activity.contract.Main9Contract;
import com.baselibrary.test.app.AppContext;
import com.baselibrary.test.bean.listJson;

import java.util.Hashtable;

/**
 * Created by Administrator 于萌萌
 * 创建日期: 11:35 . 2017年03月06日
 * 描述:
 * <p>
 * <p>
 * 备注:
 */
public class Main9Model implements Main9Contract.Model {

    @Override
    public void getData(final Main9Contract.getDatas getDatas) {
        String url1 = AppContext.getUrl()+"listJson.txt";
        Hashtable<String, String> hashtable = new Hashtable<>();
        Request_netWork netWork = new Request_netWork("listJson", url1, hashtable);
        //是否设置 和 显示 缓存
      //  netWork.setCahce(chengshibean.class);

        NetTool.getInstances().getRequests()
                .jsonBean(listJson.class)
                .setRequests(netWork)
                .sendRequests(new BaseObserver.CallBack<listJson>() {
                    @Override
                    public void succeed(listJson listJson) {
                        LogUtils.i("现在是我\t"+"mObserver1"+"专属成功是"+listJson);
                        getDatas.getDatatas(listJson);
                    }

                    @Override
                    public void updata(int updata) {
                        LogUtils.i("现在是我\t"+"mObserver1"+"专属过程是"+updata);
                    }

                    @Override
                    public void failure(Request_netWork_error o) {
                        LogUtils.i("现在是我\t"+"mObserver1"+"专属失败是"+o);
                    }

                    @Override
                    public void start(Request_netWork observable, listJson listJson) {
                        LogUtils.i("现在是我\t"+"mObserver1"+"专属开始是"+Thread.currentThread().getName());
                        LogUtils.i("缓存\t"+"mObserver1"+"专属开始是"+listJson);
                        //  Object clazz = ()observable.getClazz();

                        UtilsToast.showToast(AppContext.getApplication(),"mObserver1开始");
                       // if (null!=listJson)
                           // view.succeed(chengshibean);
                    }

                });

        AppContext.getmControlQueue().add(netWork);
    }
}
